home *** CD-ROM | disk | FTP | other *** search
/ Macworld Expo - Develope…Central & Net Innovations / Developer Central and Net Innovators (MacWorld Expo) (January 1999).iso / Developer Central / Bowers Development / Demo AppMaker / Examples / PowerPlant / Everything / CModalRadios.cp < prev    next >
Encoding:
Text File  |  1998-10-11  |  8.1 KB  |  442 lines  |  [TEXT/CWIE]

  1. // CModalRadios.cp -- dialog methods
  2.  
  3. #include "CModalRadios.h"
  4.  
  5. #include <UEnvironment.h>
  6. #include <UReanimator.h>
  7. #include <URegistrar.h>
  8. #include <LStream.h>
  9. #include <LTabGroup.h>
  10. #include <LPushButton.h>
  11. #include <LAMPushButtonImp.h>
  12. #include <LGAPushButtonImp.h>
  13. #include <LRadioGroupView.h>
  14. #include <LRadioButton.h>
  15. #include <LAMControlImp.h>
  16. #include <LGARadioButtonImp.h>
  17. #include <LTextGroupBox.h>
  18. #include <LAMControlViewImp.h>
  19. #include <LGATextGroupBoxImp.h>
  20. #include <CustomControls.h>
  21. #include <LBevelButton.h>
  22. #include <LAMBevelButtonImp.h>
  23. #include <LGABevelButtonImp.h>
  24. #include <LTextButton.h>
  25. #include <CTextUtils.h>
  26.  
  27. #include "DModalRadiosData.h"
  28. #include "EverythingCmds.h"
  29. #include <PP_Messages.h>
  30.  
  31.  
  32. #define PPob_ModalRadiosID    210
  33. #define RidL_ModalRadiosID    210
  34.  
  35. Boolean        CModalRadios::sIsRegistered = false;
  36.  
  37. //----------
  38. CModalRadios*        CModalRadios::CreateModalRadios (
  39.     LCommander*        inSuperCommander,
  40.     CommandT        inCommand,
  41.     DModalRadiosData*        inData)
  42. {
  43.     if (!sIsRegistered) {
  44.         RegisterClass ();
  45.     }
  46.     CModalRadios*        dlog;
  47.     dlog = ((CModalRadios *)LWindow::CreateWindow(PPob_ModalRadiosID, inSuperCommander));
  48.     dlog->mCommand = inCommand;
  49.     dlog->SetFromData (inData);
  50.  
  51.     return dlog;
  52. }
  53.  
  54. //----------
  55. #define    RegisterClasses(AbstractClass,AMImpClass,GAImpClass)    \
  56.     RegisterClass_(AbstractClass);    \
  57.     if (useAppearance) {    \
  58.         RegisterClassID_(AMImpClass, AbstractClass::imp_class_ID);    \
  59.     } else {    \
  60.         RegisterClassID_(GAImpClass, AbstractClass::imp_class_ID);    \
  61.     }
  62.  
  63. //----------
  64. void    CModalRadios::RegisterClass ()
  65. {
  66.     Boolean        useAppearance = UEnvironment::HasFeature (env_HasAppearance);
  67.  
  68.     RegisterClass_(CModalRadios);
  69.  
  70.     // register the pane classes we use
  71.     RegisterClasses (LPushButton, LAMPushButtonImp, LGAPushButtonImp);
  72.     RegisterClass_(LRadioGroupView);
  73.     RegisterClasses (LRadioButton, LAMControlImp, LGARadioButtonImp);
  74.     RegisterClasses (LTextGroupBox, LAMControlViewImp, LGATextGroupBoxImp);
  75.     RegisterClasses (CRadioButton, CustomControlImp, CustomControlImp);
  76.     RegisterClasses (LBevelButton, LAMBevelButtonImp, LGABevelButtonImp);
  77.     RegisterClass_(LTextButton);
  78.  
  79.     sIsRegistered = true;
  80. }
  81.  
  82. //----------
  83. CModalRadios::CModalRadios (
  84.     LStream*    inStream)
  85.     : LGADialog (inStream)
  86. {
  87.     mData = nil;
  88. }
  89.  
  90. //----------
  91. CModalRadios::~CModalRadios()
  92. {
  93.     delete mData;
  94. }
  95.  
  96. //----------
  97. //    This member function gets called once the containment hierarchy that contains
  98. //    this pane has been built. It gives us a chance to get data members for
  99. //    interesting subviews, and to do other operations now that our subviews exist.
  100. void    CModalRadios::FinishCreateSelf()
  101. {
  102.     LGADialog::FinishCreateSelf();
  103.  
  104.     mOKButton = (LPushButton*) FindPaneByID ('OK  ');
  105.  
  106.     mRadioGroupGroup = (LRadioGroupView*) FindPaneByID ('Radp');
  107.  
  108.     mStandardRadio = (LRadioButton*) FindPaneByID ('Stad');
  109.  
  110.     mGroupGroup = (LRadioGroupView*) FindPaneByID ('Grop');
  111.  
  112.     mGraphicGroup = (LRadioGroupView*) FindPaneByID ('Grac');
  113.  
  114.     mStopRadio = (CRadioButton*) FindPaneByID ('Stop');
  115.  
  116.     mGoRadio = (CRadioButton*) FindPaneByID ('Go  ');
  117.  
  118.     mBevelGroup = (LRadioGroupView*) FindPaneByID ('Bevl');
  119.  
  120.     mRadioButtonRadio = (LBevelButton*) FindPaneByID ('Radn');
  121.  
  122.     mRadioButton2Radio = (LBevelButton*) FindPaneByID ('Rad2');
  123.  
  124.     mTextGroup = (LRadioGroupView*) FindPaneByID ('Text');
  125.  
  126.     mNameRadio = (LTextButton*) FindPaneByID ('Name');
  127.  
  128.     mKindRadio = (LTextButton*) FindPaneByID ('Kind');
  129.  
  130.     mSizeRadio = (LTextButton*) FindPaneByID ('Size');
  131.  
  132.  
  133.     UReanimator::LinkListenerToControls(this, this, RidL_ModalRadiosID);
  134.         // the purpose is to "connect" self to whatever controls
  135.         // that we want to "listen" to
  136.  
  137. // any additional initialization for your dialog:
  138.  
  139. }
  140.  
  141. //----------
  142. void    CModalRadios::SetFromData (
  143.     DModalRadiosData*        inData)
  144. {
  145.     mData = inData;
  146.     mData->AddListener (this);
  147.  
  148.     mRadioGroupGroup->SetValue (mData->GetRadioGroup2 ());
  149.     mGroupGroup->SetValue (mData->GetGroup2 ());
  150.     mGraphicGroup->SetValue (mData->GetGraphic3 ());
  151.     mBevelGroup->SetValue (mData->GetBevel2 ());
  152.     mTextGroup->SetValue (mData->GetText2 ());
  153. }
  154.  
  155. //----------
  156. DModalRadiosData*        CModalRadios::GetData ()
  157. {
  158.  
  159.     return mData;
  160. }
  161.  
  162. //----------
  163. void    CModalRadios::DataChanged (
  164.     long        inDataID)
  165. {
  166.     StopListening ();
  167.  
  168.     if (inDataID == idRadioGroup2) {
  169.         mRadioGroupGroup->SetValue (mData->GetRadioGroup2 ());
  170.     }
  171.     if (inDataID == idGroup2) {
  172.         mGroupGroup->SetValue (mData->GetGroup2 ());
  173.     }
  174.     if (inDataID == idGraphic3) {
  175.         mGraphicGroup->SetValue (mData->GetGraphic3 ());
  176.     }
  177.     if (inDataID == idBevel2) {
  178.         mBevelGroup->SetValue (mData->GetBevel2 ());
  179.     }
  180.     if (inDataID == idText2) {
  181.         mTextGroup->SetValue (mData->GetText2 ());
  182.     }
  183.  
  184.     StartListening ();
  185. }
  186.  
  187. //----------
  188. void    CModalRadios::ListenToMessage (
  189.     MessageT    inMessage,
  190.     void        *ioParam)
  191. {
  192.     switch (inMessage) {
  193.     case msg_OK:
  194.             GetSuperCommander()->ProcessCommand(-mCommand, this);
  195.         break;
  196.  
  197.     case msg_Cancel:
  198.             DoClose();
  199.         break;
  200.  
  201.     case msgDataChanged:
  202.             DataChanged ((long)ioParam);
  203.         break;
  204.  
  205.  
  206.     default:
  207.           ; // do something
  208.         break;
  209.     }
  210. }
  211.  
  212. //----------
  213. Boolean        CModalRadios::ObeyCommand (
  214.     CommandT    inCommand,
  215.     void*        ioParam)
  216. {
  217.     Boolean        cmdHandled = true;
  218.  
  219.     if (inCommand < 0) {
  220.         // modal dialog has finished
  221.  
  222.         switch (-inCommand) {
  223.         }
  224.  
  225.     } else {
  226.         switch (inCommand) {
  227.  
  228.         default:
  229.                 cmdHandled = LGADialog::ObeyCommand(inCommand, ioParam);
  230.             break;
  231.         }
  232.     }
  233.  
  234.     return cmdHandled;
  235. }
  236.  
  237. //----------
  238. void    CModalRadios::FindCommandStatus (
  239.     CommandT    inCommand,
  240.     Boolean        &outEnabled,
  241.     Boolean        &outUsesMark,
  242.     Char16        &outMark,
  243.     Str255        outName)
  244. {
  245.     outUsesMark = false;
  246.  
  247.     switch (inCommand) {
  248.  
  249.     // +++ Add cases here for the commands you handle
  250.  
  251.     default:
  252.             LGADialog::FindCommandStatus(inCommand, outEnabled,
  253.                                             outUsesMark, outMark, outName);
  254.         break;
  255.     }
  256. }
  257.  
  258. // following functions will be obsoleted
  259. // retained only for backwards compatibility
  260. //----------
  261. Int32
  262. CModalRadios::GetRadioGroupGroupChoice ()
  263. {
  264.     return mRadioGroupGroup->GetCurrentRadioID ();
  265. }
  266.  
  267. void
  268. CModalRadios::SetRadioGroupGroupChoice (
  269.     Int32        choice)
  270. {
  271.     mRadioGroupGroup->SetCurrentRadioID (choice);
  272. }
  273.  
  274. //----------
  275. Boolean
  276. CModalRadios::GetStandardValue ()
  277. {
  278.     return mStandardRadio->GetValue ();
  279. }
  280.  
  281. void
  282. CModalRadios::SetStandardValue (
  283.     Boolean        inValue)
  284. {
  285.     mStandardRadio->SetValue (inValue);
  286. }
  287.  
  288. //----------
  289. Int32
  290. CModalRadios::GetGroupGroupChoice ()
  291. {
  292.     return mGroupGroup->GetCurrentRadioID ();
  293. }
  294.  
  295. void
  296. CModalRadios::SetGroupGroupChoice (
  297.     Int32        choice)
  298. {
  299.     mGroupGroup->SetCurrentRadioID (choice);
  300. }
  301.  
  302. //----------
  303. Int32
  304. CModalRadios::GetGraphicGroupChoice ()
  305. {
  306.     return mGraphicGroup->GetCurrentRadioID ();
  307. }
  308.  
  309. void
  310. CModalRadios::SetGraphicGroupChoice (
  311.     Int32        choice)
  312. {
  313.     mGraphicGroup->SetCurrentRadioID (choice);
  314. }
  315.  
  316. //----------
  317. Boolean
  318. CModalRadios::GetStopValue ()
  319. {
  320.     return mStopRadio->GetValue ();
  321. }
  322.  
  323. void
  324. CModalRadios::SetStopValue (
  325.     Boolean        inValue)
  326. {
  327.     mStopRadio->SetValue (inValue);
  328. }
  329.  
  330. //----------
  331. Boolean
  332. CModalRadios::GetGoValue ()
  333. {
  334.     return mGoRadio->GetValue ();
  335. }
  336.  
  337. void
  338. CModalRadios::SetGoValue (
  339.     Boolean        inValue)
  340. {
  341.     mGoRadio->SetValue (inValue);
  342. }
  343.  
  344. //----------
  345. Int32
  346. CModalRadios::GetBevelGroupChoice ()
  347. {
  348.     return mBevelGroup->GetCurrentRadioID ();
  349. }
  350.  
  351. void
  352. CModalRadios::SetBevelGroupChoice (
  353.     Int32        choice)
  354. {
  355.     mBevelGroup->SetCurrentRadioID (choice);
  356. }
  357.  
  358. //----------
  359. Boolean
  360. CModalRadios::GetRadioButtonValue ()
  361. {
  362.     return mRadioButtonRadio->GetValue ();
  363. }
  364.  
  365. void
  366. CModalRadios::SetRadioButtonValue (
  367.     Boolean        inValue)
  368. {
  369.     mRadioButtonRadio->SetValue (inValue);
  370. }
  371.  
  372. //----------
  373. Boolean
  374. CModalRadios::GetRadioButton2Value ()
  375. {
  376.     return mRadioButton2Radio->GetValue ();
  377. }
  378.  
  379. void
  380. CModalRadios::SetRadioButton2Value (
  381.     Boolean        inValue)
  382. {
  383.     mRadioButton2Radio->SetValue (inValue);
  384. }
  385.  
  386. //----------
  387. Int32
  388. CModalRadios::GetTextGroupChoice ()
  389. {
  390.     return mTextGroup->GetCurrentRadioID ();
  391. }
  392.  
  393. void
  394. CModalRadios::SetTextGroupChoice (
  395.     Int32        choice)
  396. {
  397.     mTextGroup->SetCurrentRadioID (choice);
  398. }
  399.  
  400. //----------
  401. Boolean
  402. CModalRadios::GetNameValue ()
  403. {
  404.     return mNameRadio->GetValue ();
  405. }
  406.  
  407. void
  408. CModalRadios::SetNameValue (
  409.     Boolean        inValue)
  410. {
  411.     mNameRadio->SetValue (inValue);
  412. }
  413.  
  414. //----------
  415. Boolean
  416. CModalRadios::GetKindValue ()
  417. {
  418.     return mKindRadio->GetValue ();
  419. }
  420.  
  421. void
  422. CModalRadios::SetKindValue (
  423.     Boolean        inValue)
  424. {
  425.     mKindRadio->SetValue (inValue);
  426. }
  427.  
  428. //----------
  429. Boolean
  430. CModalRadios::GetSizeValue ()
  431. {
  432.     return mSizeRadio->GetValue ();
  433. }
  434.  
  435. void
  436. CModalRadios::SetSizeValue (
  437.     Boolean        inValue)
  438. {
  439.     mSizeRadio->SetValue (inValue);
  440. }
  441.  
  442.